home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / archives / com / internet / sting / time.lzh / T_SERVER / T_SERVER.S < prev   
Text File  |  1997-08-09  |  25KB  |  899 lines

  1. ;----------------------------------------------------------------------------
  2. ;File name:    T_SERVER.S            Revision date:    1997.08.09
  3. ;Creator:    Ulf Ronald Andersson        Creation date:    1997.07.31
  4. ;(c)1996 by:    Ulf Ronald Andersson        All rights reserved
  5. ;----------------------------------------------------------------------------
  6. ;Required header declarations:
  7. ;
  8.     .include    "uran\STRUCT.SH"    ;PASM adapted structures
  9.     .include    "uran\URAn_SYS.SH"    ;Main system definitions
  10.     .include    "uran\URAn_LA.SH"    ;Line A variables etc
  11.     .include    "uran\URAn_DOS.SH"    ;GEMDOS, BIOS, XBIOS
  12.     .include    "uran\URAn_GEM.SH"    ;VDI & AES
  13.     .include    "uran\URAn_SIM.SH"    ;some AES funcs for TOS/TTP
  14.     .include    "uran\URAn_APP.SH"    ;General application support
  15.     .include    "uran\URAn_JAR.SH"    ;Cookie jar handling
  16.     .include    "uran\URAn_AV.SH"    ;AV/VA protocol + MP protocol
  17. ;
  18.     .include    "sting\LAYER.SH"    ;only used by servers
  19.     .include    "sting\TRANSPRT.SH"    ;used by servers/clients
  20.     .include    "sting\NET_TCON.SH"    ;handles network time conv.
  21.     .include    "sting\DOMAIN.SH"    ;handles domain name/ip conv.
  22. ;
  23. ;----------------------------------------------------------------------------
  24. ;
  25. ZERO_IP        equ    0
  26. DAY_TIME_PORT    equ    13
  27. NET_TIME_PORT    equ    37
  28. TOS_NORMAL    equ    0
  29. BUF_SIZE    equ    500
  30. ;
  31. ;----------------------------------------------------------------------------
  32. ;
  33. ;;;huge_program        = 1    ;uncomment if TEXT+DATA sections are > 32KB
  34. ;;;keep_windows        = 1    ;uncomment to keep ACC vwk in main eventloop
  35. exec_timeout        = 100    ;uncomment to enable timer in main eventloop
  36. exec_message        = 1    ;uncomment for messages in main eventloop
  37. ;
  38. ;----------------------------------------------------------------------------
  39. ;
  40.     .text
  41. ;
  42.     start_app
  43. ;
  44. ;----------------------------------------------------------------------------
  45. ;
  46.     .ifeq    huge_program
  47.     .data
  48.     .endif
  49. ;
  50. acc_name:
  51.     dc.b    '  Time server',NUL    ;for ACC menu registration
  52.     dc.b    NUL
  53.     even
  54. ;
  55. id_app_name_s:
  56.     dc.b    'T_SERVER',NUL
  57.     even
  58. ;
  59. ;----------------------------------------------------------------------------
  60. ;
  61.     .ifeq    huge_program
  62.     .bss
  63.     .endif
  64. ;
  65. message:    ds.w    8        ;evnt_mesag message pipe
  66. intin:        ds.w    30        ;30 words or more for AES/VDI
  67. intout:        ds.w    45        ;45 words or more for AES/VDI
  68. ptsin:        ds.w    30        ;30 words or more for VDI
  69. ptsout:        ds.w    12        ;12 words or more for VDI output coordinates
  70.         ds.l    200        ;subroutine stack >= 100 longs
  71. mystack:    ds.l    1        ;top of subroutine stack
  72. ;
  73. ;----------------------------------------------------------------------------
  74. ;
  75.     .text
  76. ;
  77. ;----------------------------------------------------------------------------
  78. ;    Constants, Variables, and Usage of the URAn_APP.S library
  79. ;
  80. ;rz        'relative zero' for internal references
  81. ;basepage_p    -> program's base page
  82. ;tsr_size    .L size of BASEPAGE+TEXT+DATA+BSS  (only TOS/TTP may TSR)
  83. ;progtype    .L indicates program type:
  84. ;  ...            $0000.$FFFF == TOS/TTP/boot_PRG
  85. ;  ...            $0000.ap_id == APP/GTP/non_boot_PRG
  86. ;  ...            $FFFF.ap_id == ACC
  87. ;acc_flag    is the high word of 'progtype'
  88. ;tos_flag    is the low word of 'progtype'
  89. ;bootflag    .W $FFFF == PRG booted from AUTO (also sets 'tos_flag')
  90. ;menu_id    .W menu id for an ACC, otherwise null
  91. ;g_handle    .W workstation handle for ACC/APP/GTP/non_boot_PRG
  92. ;vwk_handle    .W virtual workstation handle
  93. ;contrl        12 words for AES/VDI control data
  94. ;
  95. ;wk_x_rez \
  96. ;wk_y_rez  \/ from
  97. ;wk_pix_w  /\ opnvwk
  98. ;wk_pix_h /
  99. ;
  100. ;MiNT_p        .L NULL or -> MiNT structure
  101. ;MagX_p        .L NULL or -> MagX structure
  102. ;nAES_p        .L NULL or -> nAES structure
  103. ;Gnva_p        .L NULL or -> Gnva structure
  104. ;
  105. ;line_a_base_p    .L -> line_a variable base
  106. ;kbshift_p    .L -> kbshift byte of OS
  107. ;currbp_p_p    .L -> OS var -> current basepage
  108. ;
  109. ;NB: if symbol 'huge_program' is defined, above data is in TEXT section (else in BSS)
  110. ;NB: defining 'huge_program' also makes function calls use 'jsr' (instead of bsr)
  111. ;
  112. ;Required user routines:
  113. ;
  114. ;init_app    called for ACC/APP/GTP/non_boot_PRG to init application,
  115. ;        but doesn't need appl_init, graf_handle, or v_opnvwk,
  116. ;        nor does an ACC need menu_register.
  117. ;        Suitable use is for initialization of object trees.
  118. ;NB:  for ACC    menu_register is called between init_app and exec_app
  119. ;
  120. ;exec_app    called to execute the main application regardless of type,
  121. ;        but doesn't need v_clsvwk, or appl_exit, or ACC appl_mesag.
  122. ;        This call will be repeated for a reactivated ACC.
  123. ;        Non_acc programs should have exit code in d0 at RTS.
  124. ;        (See details at 'Exit codes:' below)
  125. ;
  126. ;    At entry to either of these two routines:
  127. ;
  128. ;        d6.W    == bootflag    \
  129. ;        d7.L    == progtype     > See descriptions above.
  130. ;        a6.L    == rz        /
  131. ;
  132. ;Optional user routines:
  133. ;
  134. ;exec_timer    Called for ACC that has a defined constant 'exec_timeout',
  135. ;        whenever evnt_multi produces such a timer event.
  136. ;        The constant is placed as long at 'main_timeout', and may
  137. ;        there be dynamically adjusted by the program.
  138. ;
  139. ;exec_mesag    Called for ACC that has a defined constant 'exec_message',
  140. ;        whenever evnt_multi/evnt_mesag produces messages that are
  141. ;        not AC_OPEN  (such as VA_START).
  142. ;
  143. ;        If the constant 'keep_windows' is also set, the workstation
  144. ;        will not be closed at each return (you must obey AC_CLOSE).
  145. ;        This places a word == $FF00 at 'keep_wind_f', and if the top
  146. ;        byte is cleared the workstation closure is enabled again.
  147. ;
  148. ;NB:    Top bit of the word 'revise_type_f' is used for 3 purposes:
  149. ;   1:    Let ACC start 'exec_app' directly without awaiting event.
  150. ;   2:    Let APP delay 'exec_app' until an event occurs.
  151. ;   3:    Let APP loop back for more events after 'exec_app'
  152. ;The flag must be set by 'init_app' in the first two cases, and in case 3
  153. ;should be set/cleared in 'exec_app' to decide whether to exit program.
  154. ;
  155. ;Exit codes:    At exit from exec_app, d0 has the following effects
  156. ;        when the program was not started as accessory.
  157. ;
  158. ; negative    => Pterm(d0)            => error code exit
  159. ; 0        => Pterm(d0)            => error free exit
  160. ; 0x0000ADD0    => Ptermres(tsr_size,0)        => error free resident exit
  161. ; 0x0000ADD1    => Ptermres(d1,0)        => error free resident exit
  162. ; 0x0000ADD2    => Ptermres(d1,d2)        => error code resident exit
  163. ;
  164. ;----------------------------------------------------------------------------
  165. ;Start of:    init_app
  166. ;----------------------------------------------------------------------------
  167. ;
  168. init_app:
  169. ;
  170.     include        "uran\URAn_ARG.S"        ;load ARGV handler
  171. ;
  172. ; Here URAn_ARG.S defines two variables
  173. ;
  174. ;arg_cnt    == number of strings on command line
  175. ;arg_ptr    -> NUL_separated argument strings + final NUL
  176. ;
  177. ;NB:    Both of the above include a dummy program name (first string==NUL).
  178. ;-------
  179.     st        fatal_f            ;assume fatal errors can happen
  180.     gemdos        Super,0.w
  181.     move.l        d0,d4
  182.     eval_cookie    #"STiK"
  183.     move.l        d0,d3                ;d3 = d0 -> DRV_LIST structure
  184.     gemdos        Super|_ind,d4
  185.     move.l        d3,sting_drivers        ;sting_drivers -> DRV_LIST structure
  186.     ble        .STiK_not_found
  187.     move.l        d3,a3                ;a3 -> DRV_LIST structure
  188.     lea        DRV_LIST_magic(a3),a0
  189.     lea        STiKmagic_s(pc),a1
  190.     moveq        #10-1,d0
  191. .strcmp_loop:                    ;loop to test STiKmagic of DRV_LIST
  192.     cmpm.b        (a0)+,(a1)+
  193.     dbne        d0,.strcmp_loop
  194.     bne        .STiK_not_valid
  195. ;
  196.     move.l        DRV_LIST_get_dftab(a3),a0    ;a0 -> get_dftab function
  197.     pea        TRANSPORT_DRIVER_s        ;-(sp) = "TRANSPORT_TCPIP"
  198.     jsr        (a0)                ;call get_dftab
  199.     addq        #4,sp
  200.     move.l        d0,tpl                ;store pointer in 'tpl'
  201.     ble        .driver_not_valid
  202. ;
  203.     move.l        DRV_LIST_get_dftab(a3),a0    ;a0 -> get_dftab function
  204.     pea        MODULE_DRIVER_s            ;-(sp) = "MODULE_LAYER"
  205.     jsr        (a0)                ;call get_dftab
  206.     addq        #4,sp
  207.     move.l        d0,stx                ;store pointer in 'tpl'
  208.     ble.s        .layer_not_valid
  209.     clr        fatal_f
  210. ;
  211.     bsr        update_ports
  212.     move.l        daytime_tcp_h,d3
  213.     and.l        daytime_udp_h,d3
  214.     and.l        nettime_tcp_h,d3
  215.     and.l        nettime_udp_h,d3
  216.     bmi.s        .no_ports_open
  217.     clr.l        initerr_mess_p
  218.     rts
  219. ;
  220. .STiK_not_found:
  221.     lea        STiK_not_found_al_s,a0
  222.     bra.s        .init_error
  223. ;
  224. .STiK_not_valid:
  225.     lea        STiK_not_valid_al_s,a0
  226.     bra.s        .init_error
  227. ;
  228. .driver_not_valid:
  229.     lea        driver_not_valid_al_s,a0
  230.     bra.s        .init_error
  231. ;
  232. .layer_not_valid:
  233.     lea        layer_not_valid_al_s(pc),a0
  234.     bra.s        .init_error
  235. ;
  236. .no_ports_open:
  237.     lea        no_ports_open_al_s,a0
  238. .init_error:
  239.     move.l        a0,initerr_mess_p
  240.     rts
  241. ;
  242. ;----------------------------------------------------------------------------
  243. ;End of:    init_app
  244. ;----------------------------------------------------------------------------
  245. ;Start of:    exec_app
  246. ;----------------------------------------------------------------------------
  247. ;
  248. exec_app:
  249.     move.l        initerr_mess_p,d3
  250.     beq.s        no_init_err
  251.     move.l        d3,a3
  252.     sim_aes        form_alert,#1,(a3)
  253.     tst        fatal_f
  254.     bne        exit_exec_err
  255. no_init_err:
  256.     tst.w        d7            ;GEM/TOS program ?
  257.     bmi.s        exec_TOS        ;go show error message and exit for TOS program
  258. exec_GEM:
  259.     tst.l        d7            ;APP/ACC program ?
  260.     bmi        exec_multi_GEM
  261.     cmp        #1,global+2        ;Singletasking APP ?
  262.     beq.s        exec_single_GEM        ;then go show error message and exit program
  263. exec_multi_APP:
  264.     btst        #7,revise_type_f    ;been here before ?
  265.     bne        exec_multi_GEM        ;then behave like an ACC this time
  266.     tst.l        d3            ;init_error ?
  267.     bne.s        exit_exec_err        ;go exit program on init errors (bad STiK etc)
  268.     bset        #7,revise_type_f    ;tell main loop to behave like ACC
  269.     bra        exit_exec_ok        ;exit to main event loop
  270. ;
  271. ;-------------------------------------
  272. ;
  273. exec_TOS:
  274.     lea        must_be_GEM_al_s,a3
  275.     bra.s        exec_APP_error
  276. ;
  277. ;-------------------------------------
  278. ;
  279. exec_single_GEM:
  280.     lea        must_be_multi_al_s,a3
  281. exec_APP_error:
  282.     sim_aes        form_alert,#1,(a3)
  283. exit_exec_err:
  284.     moveq        #-1,d0
  285. exit_terminate:
  286.     move.l        d0,d3
  287.     bclr        #7,revise_type_f
  288.     lea        daytime_tcp_h(pc),a3
  289.     bsr        close_tcp_port
  290.     lea        daytime_udp_h(pc),a3
  291.     bsr        close_udp_port
  292.     lea        nettime_tcp_h(pc),a3
  293.     bsr        close_tcp_port
  294.     lea        nettime_udp_h(pc),a3
  295.     bsr        close_udp_port
  296.     move.l        d3,d0
  297.     bra.s        exit_exec_app
  298. ;
  299. ;-------------------------------------
  300. ;
  301. exec_multi_GEM:
  302.     bsr        update_ports
  303.     gem_aes     form_alert,#1,hello_there_al_s
  304.     cmp        #1,d0    ;OK button ?
  305.     beq.s        exit_exec_ok
  306.     cmp        #2,d0    ;Time button
  307.     bne.s        exit_exec_ok
  308.     bsr        time_display_alert
  309. exit_exec_ok:
  310.     clr.l    d0
  311. exit_exec_app:
  312.     rts
  313. ;
  314. ;----------------------------------------------------------------------------
  315. ;End of:    exec_app
  316. ;----------------------------------------------------------------------------
  317. ;Start of:    exec_timer
  318. ;----------------------------------------------------------------------------
  319. ;
  320.     .ifne    exec_timeout    ;cond:    ifne exec_timeout
  321. exec_timer:
  322.     lea    nettime_tcp_h(pc),a3
  323.     tst    (a3)
  324.     bmi.s    .done_net_TCP
  325.     CNbyte_count    (a3)
  326.     tst    d0
  327.     bmi.s    .done_net_TCP
  328.     bsr    service_nettime_TCP
  329. .done_net_TCP:
  330.     lea    nettime_udp_h(pc),a3
  331.     tst    (a3)
  332.     bmi.s    .done_net_UDP
  333.     CNget_NDB    (a3)
  334.     tst.l    d0
  335.     beq.s    .done_net_UDP
  336.     bsr    service_nettime_UDP
  337. .done_net_UDP:
  338.     lea    daytime_tcp_h(pc),a3
  339.     tst    (a3)
  340.     bmi.s    .done_day_TCP
  341.     CNbyte_count    (a3)
  342.     tst    d0
  343.     bmi.s    .done_day_TCP
  344.     bsr    service_daytime_TCP
  345. .done_day_TCP:
  346.     lea    daytime_udp_h(pc),a3
  347.     tst    (a3)
  348.     bmi.s    .done_day_UDP
  349.     CNget_NDB    (a3)
  350.     tst.l    d0
  351.     beq.s    .done_day_UDP
  352.     bsr    service_daytime_UDP
  353. .done_day_UDP:
  354. exit_exec_timer:
  355.     rts
  356.     .endif            ;ends:    ifne exec_timeout
  357. ;
  358. ;----------------------------------------------------------------------------
  359. ;End of:    exec_timer
  360. ;----------------------------------------------------------------------------
  361. ;Start of:    exec_mesag
  362. ;----------------------------------------------------------------------------
  363. ;
  364.     .if    exec_message
  365. exec_mesag:
  366.     cmp        #AC_CLOSE,message
  367.     bne.s        .not_AC_CLOSE
  368.     sf        keep_wind_f
  369.     bra        exit_exec_mesag
  370. ;
  371. .not_AC_CLOSE:
  372.     cmp        #AP_TERM,message
  373.     bne.s        .not_AP_TERM
  374.     tst.l        d7
  375.     bmi        exit_exec_mesag        ;AP_TERM is not for ACCs
  376.     clr.l        d0            ;flag no error
  377.     bra        exit_terminate
  378. ;
  379. .not_AP_TERM:
  380.     cmp        #VA_START,message
  381.     bne.s        .not_VA_START
  382.     st        VA_START_f
  383.     move        message+2,AV_partner_id
  384.     move.l        message+6,VA_START_cmd_p
  385.     AV_send        PROTOKOLL,#w_VA_START+w_AV_STARTED_A,id_app_name_s
  386. ;
  387. ;Add ALL handling of the passed command line here, if you need to do some later
  388. ;you must copy it here, because the original may disappear after AV_STARTED.
  389. ;
  390.     AV_send.i    STARTED,VA_START_cmd_p
  391.     bra        exec_app
  392. ;
  393. .not_VA_START:
  394.     cmp        #VA_PROTOSTATUS,message
  395.     bne.s        .not_VA_PROTOSTATUS
  396.     move        message+8,VA_protostatus
  397.     move        message+6,VA_protostatus+2
  398.     bra        exit_exec_mesag
  399. ;
  400. .not_VA_PROTOSTATUS:
  401. exec_mesag_extend:
  402. ;
  403. ;Add client/server dependent message event work here
  404. ;
  405. exit_exec_mesag:
  406.     rts
  407.     .endif
  408. ;
  409. ;----------------------------------------------------------------------------
  410. ;End of:    exec_mesag
  411. ;----------------------------------------------------------------------------
  412. ;Start of:    subroutines
  413. ;----------------------------------------------------------------------------
  414. ;
  415. time_display_alert:
  416.     lea        tcon_data(pc),a0    ;a0 -> our tcon structure
  417. .alert_loop:
  418.     move.l        tcon_zoneseconds(a0),-(sp)
  419.     move.l        tcon_summer(a0),-(sp)
  420.     tcon_real2tos                ;get realtime in TOS form
  421.     tcon_tos2man                ;convert to human form
  422.     tcon_man2net
  423.     tst        GMT_f            ;GMT or Local time ?
  424.     beq.s        .keep_zone
  425.     clr.l        tcon_zoneseconds(a0)    ;enforce GMT
  426.     clr.l        tcon_summer(a0)        ;suppress daylight savings
  427. .keep_zone:
  428.     tcon_net2man
  429.     lea        buffer(pc),a1        ;prep for date string conv
  430.     bsr        man2alert        ;convert to alert  d0 = len
  431.     gem_aes        form_alert,#1,(a1)
  432.     lea        tcon_data(pc),a0
  433.     move.l        (sp)+,tcon_summer(a0)
  434.     move.l        (sp)+,tcon_zoneseconds(a0)
  435.     cmp        #2,d0            ;GMT/LOCAL button ?
  436.     bne.s        .exit
  437.     eor        #$FF,GMT_f
  438.     bra.s        .alert_loop
  439. ;    
  440. .exit:
  441.     clr        GMT_f
  442.     rts
  443. ;
  444. ;----------------------------------------------------------------------------
  445. ;
  446. update_ports:
  447.     movem.l        d0/d3/a0/a3-a4,-(sp)
  448.     lea        tcon_data(pc),a0
  449.     tcon_rd_zone
  450.     tcon_rd_summer
  451. ;
  452.     moveq        #DAY_TIME_PORT,d3
  453.     lea        daytime_tcp_h(pc),a3
  454.     lea        day_tcp_s(pc),a4
  455.     bsr        update_tcp_port
  456.     lea        daytime_udp_h(pc),a3
  457.     lea        day_udp_s(pc),a4
  458.     bsr        update_udp_port
  459.     moveq        #NET_TIME_PORT,d3
  460.     lea        nettime_tcp_h(pc),a3
  461.     lea        net_tcp_s(pc),a4
  462.     bsr        update_tcp_port
  463.     lea        nettime_udp_h(pc),a3
  464.     lea        net_udp_s(pc),a4
  465.     bsr        update_udp_port
  466.     movem.l        (sp)+,d0/d3/a0/a3-a4
  467.     rts
  468. ;
  469. ;----------------------------------------------------------------------------
  470. ;
  471. update_tcp_port:
  472.     movem.l        d0-d2/a0-a2/a5,-(sp)
  473.     lea        three2upper(pc),a5
  474.     tst        (a3)
  475.     bpl.s        .port_ok
  476.     TCP_open    #ZERO_IP,d3,#TOS_NORMAL,#BUF_SIZE
  477.     move        d0,(a3)
  478.     bpl.s        .port_ok
  479.     lea        three2lower(pc),a5
  480. .port_ok:
  481.     jsr        (a5)
  482.     movem.l        (sp)+,d0-d2/a0-a2/a5
  483.     rts
  484. ;
  485. ;----------------------------------------------------------------------------
  486. ;
  487. update_udp_port:
  488.     movem.l        d0-d2/a0-a2/a5,-(sp)
  489.     lea        three2upper(pc),a5
  490.     tst        (a3)
  491.     bpl.s        .port_ok
  492.     UDP_open    #ZERO_IP,d3
  493.     move        d0,(a3)
  494.     bpl.s        .port_ok
  495.     lea        three2lower(pc),a5
  496. .port_ok:
  497.     jsr        (a5)
  498.     movem.l        (sp)+,d0-d2/a0-a2/a5
  499.     rts
  500. ;
  501. ;----------------------------------------------------------------------------
  502. ;
  503. close_tcp_port:
  504.     tst        (a3)
  505.     bmi.s        .done_port
  506.     TCP_close    (a3),#1
  507.     st        (a3)
  508. .done_port:
  509.     rts
  510. ;
  511. ;----------------------------------------------------------------------------
  512. ;
  513. close_udp_port:
  514.     tst        (a3)
  515.     bmi.s        .done_port
  516.     UDP_close    (a3)
  517.     st        (a3)
  518. .done_port:
  519.     rts
  520. ;
  521. ;----------------------------------------------------------------------------
  522. ;
  523. three2lower:
  524.     or.b    #$20,(a4)+
  525.     or.b    #$20,(a4)+
  526.     or.b    #$20,(a4)+
  527.     rts
  528. ;
  529. ;----------------------------------------------------------------------------
  530. ;
  531. three2upper:
  532.     and.b    #$5F,(a4)+
  533.     and.b    #$5F,(a4)+
  534.     and.b    #$5F,(a4)+
  535.     rts
  536. ;
  537. ;----------------------------------------------------------------------------
  538. ;
  539. service_nettime_TCP:    ;called with d0 = CNbyte_count, (a3) = TCP_handle
  540.     lea        tcon_data(pc),a0    ;a0 -> our tcon structure
  541.     tcon_real2tos                ;get realtime in TOS form
  542.     tcon_tos2man                ;convert to human form
  543.     tcon_man2net                ;convert to network form
  544.     TCP_send    (a3),tcon_net_time(a0),#4
  545.     TCP_ack_wait    (a3),#3000
  546.     bsr        close_tcp_port
  547.     bsr        update_ports
  548.     rts    
  549. ;
  550. ;----------------------------------------------------------------------------
  551. ;
  552. service_daytime_TCP:    ;called with d0 = CNbyte_count, (a3) = TCP_handle
  553.     lea        tcon_data(pc),a0    ;a0 -> our tcon structure
  554.     bsr.s        real2daytime
  555.     lea        buffer(pc),a1        ;prep for date string conv
  556.     bsr        man2ascii        ;convert to string  d0 = len
  557.     TCP_send    (a3),(a1),d0
  558.     TCP_ack_wait    (a3),#3000
  559.     bsr        close_tcp_port
  560.     bsr        update_ports
  561.     rts    
  562. ;
  563. ;----------------------------------------------------------------------------
  564. ;
  565. real2daytime:
  566.     tcon_real2tos            ;get realtime in TOS form
  567.     tcon_tos2man            ;convert to human form
  568.     tcon_man2net            ;\/ Dummy conversion is needed
  569.     tcon_net2man            ;/\ to get the weekday correct
  570.     rts
  571. ;
  572. ;----------------------------------------------------------------------------
  573. ;
  574. service_daytime_UDP:    ;called with d0 -> NDB  (a3) = UDP_handle
  575.     move.l        d0,a4            ;a4 -> NDB
  576.     CNgetinfo    (a3)            ;For future reporting only
  577.     KRfree.i    NDB_ptr(a4)        ;release packet
  578.     KRfree        (a4)            ;release NDB
  579.     lea        tcon_data(pc),a0    ;a0 -> our tcon structure
  580.     bsr.s        real2daytime
  581.     lea        buffer(pc),a1        ;prep for date string conv
  582.     bsr        man2ascii        ;convert to string  d0 = len
  583.     UDP_send    (a3),(a1),d0
  584.     bsr        close_udp_port
  585.     bsr        update_ports
  586.     rts    
  587. ;
  588. ;----------------------------------------------------------------------------
  589. ;
  590. service_nettime_UDP:    ;called with d0 -> NDB  (a3) = UDP_handle
  591.     move.l        d0,a4            ;a4 -> NDB
  592.     CNgetinfo    (a3)            ;For future reporting only
  593.     KRfree.i    NDB_ptr(a4)        ;release packet
  594.     KRfree        (a4)            ;release NDB
  595.     lea        tcon_data(pc),a0    ;a0 -> our tcon structure
  596.     tcon_real2tos                ;get realtime in TOS form
  597.     tcon_tos2man                ;convert to human form
  598.     tcon_man2net                ;convert to network form
  599.     UDP_send    (a3),tcon_net_time(a0),#4
  600.     bsr        close_tcp_port
  601.     bsr        update_ports
  602.     rts    
  603. ;
  604. ;End of service_nettime_UDP
  605. ;----------------------------------------------------------------------------
  606. ;
  607. man2ascii:
  608.     movem.l        d1/a1-a2,-(sp)
  609.     move        tcon_man_weekday(a0),d0    ;d0 = weekday index (0==Sunday)
  610.     and        #7,d0            ;limit index
  611.     asl        #2,d0            ;scale to index pointer table
  612.     lea        weekday_spt(pc),a2    ;a2 -> table of string pointers
  613.     move.l        (a2,d0.w),a2        ;a2 -> weekday string
  614.     str_copy    a2,a1
  615.     move.b        #' ',-1(a1)
  616.     move.b        #' ',(a1)+
  617.     move        tcon_man_year(a0),d0
  618.     bsr        word2ascii4
  619.     move.b        #'.',(a1)+
  620.     move        tcon_man_month(a0),d0
  621.     bsr        word2ascii2
  622.     move.b        #'.',(a1)+
  623.     move        tcon_man_date(a0),d0
  624.     bsr        word2ascii2
  625.     move.b        #' ',(a1)+
  626.     move.b        #' ',(a1)+
  627.     move        tcon_man_hour(a0),d0
  628.     bsr        word2ascii2
  629.     move.b        #':',(a1)+
  630.     move        tcon_man_minute(a0),d0
  631.     bsr        word2ascii2
  632.     move.b        #':',(a1)+
  633.     move        tcon_man_second(a0),d0
  634.     bsr        word2ascii2
  635.     lea        GMT_tail_s(pc),a2
  636.     str_copy    a2,a1
  637.     subq        #1,a1
  638.     move.b        #'+',(a1)+
  639.     tcon_is_summer
  640.     and.l        #3600,d0
  641.     add.l        tcon_zoneseconds(a0),d0
  642.     bpl.s        .keep_sign
  643.     move.b        #'-',-1(a0)
  644.     neg.l        d0
  645. .keep_sign:
  646.     divu        #3600,d0
  647.     move.l        d0,d1
  648.     bsr        word2ascii2
  649.     move.b        #':',(a1)+
  650.     swap        d1
  651.     clr.l        d0
  652.     move        d1,d0
  653.     divu        #60,d0
  654.     bsr        word2ascii2
  655.     move.b        #CR,(a1)+
  656.     move.b        #LF,(a1)+
  657.     clr.b        (a1)+
  658.     move.l        a1,d0
  659.     movem.l        (sp)+,d1/a1-a2
  660.     sub.l        a1,d0    ;d0 = resulting string length, incl terminator
  661.     rts
  662. ;
  663. ;End of man2ascii
  664. ;----------------------------------------------------------------------------
  665. ;
  666. man2alert:
  667.     movem.l        a1-a2,-(sp)
  668.     move.b        #'[',(a1)+
  669.     move.b        #'0',(a1)+
  670.     move.b        #']',(a1)+
  671.     move.b        #'[',(a1)+
  672.     move.b        #'|',(a1)+
  673.     move.b        #' ',(a1)+
  674.     move        tcon_man_weekday(a0),d0    ;d0 = weekday index (0==Sunday)
  675.     and        #7,d0            ;limit index
  676.     asl        #2,d0            ;scale to index pointer table
  677.     lea        weekday_spt(pc),a2    ;a2 -> table of string pointers
  678.     move.l        (a2,d0.w),a2        ;a2 -> weekday string
  679.     str_copy    a2,a1
  680.     subq        #1,a1
  681.     move.b        #'|',(a1)+
  682.     move.b        #' ',(a1)+
  683.     move        tcon_man_year(a0),d0
  684.     bsr        word2ascii4
  685.     move.b        #'.',(a1)+
  686.     move        tcon_man_month(a0),d0
  687.     bsr        word2ascii2
  688.     move.b        #'.',(a1)+
  689.     move        tcon_man_date(a0),d0
  690.     bsr        word2ascii2
  691.     move.b        #' ',(a1)+
  692.     move.b        #'|',(a1)+
  693.     move.b        #' ',(a1)+
  694.     move        tcon_man_hour(a0),d0
  695.     bsr        word2ascii2
  696.     move.b        #':',(a1)+
  697.     move        tcon_man_minute(a0),d0
  698.     bsr        word2ascii2
  699.     move.b        #':',(a1)+
  700.     move        tcon_man_second(a0),d0
  701.     bsr        word2ascii2
  702.     lea        Local_s(pc),a2
  703.     tst        GMT_f
  704.     beq.s        .keep_type_1
  705.     lea        GMT_s(pc),a2
  706. .keep_type_1:
  707.     str_copy    a2,a1
  708.     subq        #1,a1
  709.     move.b        #'|',(a1)+
  710.     move.b        #']',(a1)+
  711.     move.b        #'[',(a1)+
  712.     move.b        #' ',(a1)+
  713.     move.b        #'O',(a1)+
  714.     move.b        #'k',(a1)+
  715.     move.b        #' ',(a1)+
  716.     move.b        #'|',(a1)+
  717.     lea        Local_s(pc),a2
  718.     tst        GMT_f
  719.     bne.s        .keep_type_2
  720.     lea        GMT_s(pc),a2
  721. .keep_type_2:
  722.     str_copy    a2,a1
  723.     subq        #1,a1
  724.     move.b        #']',(a1)+
  725.     move.b        #NUL,(a1)+
  726.     move.l        a1,d0
  727.     movem.l        (sp)+,a1-a2
  728.     sub.l        a1,d0    ;d0 = resulting string length, incl terminator
  729.     rts
  730. ;
  731. ;End of man2alert
  732. ;----------------------------------------------------------------------------
  733. ;
  734. word2ascii4:
  735.     and.l    #1<<16-1,d0
  736.     divu    #1000,d0
  737.     add    #'0',d0
  738.     move.b    d0,(a1)+
  739.     clr    d0
  740.     swap    d0
  741.     divu    #100,d0
  742.     add    #'0',d0
  743.     move.b    d0,(a1)+
  744.     clr    d0
  745.     swap    d0
  746. word2ascii2:
  747.     and.l    #1<<7-1,d0
  748.     divu    #10,d0
  749.     add    #'0',d0
  750.     move.b    d0,(a1)+
  751.     swap    d0
  752.     add    #'0',d0
  753.     move.b    d0,(a1)+
  754.     rts
  755. ;
  756. ;----------------------------------------------------------------------------
  757. ;End of:    subroutines
  758. ;----------------------------------------------------------------------------
  759. ;
  760.     make    SIM_links
  761.     make    JAR_links
  762.     make    TCON_links
  763.     make    DOMAIN_links
  764.     make    AV_links
  765. ;
  766. ;----------------------------------------------------------------------------
  767. ;
  768. text_limit:    .data
  769. ;
  770. ;----------------------------------------------------------------------------
  771. ;
  772. STiKmagic_s:
  773.     dc.b    'STiKmagic',NUL
  774. TRANSPORT_DRIVER_s:
  775.     dc.b    'TRANSPORT_TCPIP',NUL
  776. MODULE_DRIVER_s:
  777.     dc.b    'MODULE_LAYER',NUL
  778. ;
  779. STiK_not_found_al_s:
  780.     dc.b    '[3]['
  781.     dc.b    'STinG skeleton client/server:|'
  782.     dc.b    '-----------------------------|'
  783.     dc.b    'The STiK cookie is missing !]'
  784.     dc.b    '[ Abort ]',NUL
  785. ;
  786. STiK_not_valid_al_s:
  787.     dc.b    '[3]['
  788.     dc.b    'STinG skeleton client/server:|'
  789.     dc.b    '-----------------------------|'
  790.     dc.b    'The STiK cookie is corrupted!]'
  791.     dc.b    '[ Abort ]',NUL
  792. ;
  793. driver_not_valid_al_s:
  794.     dc.b    '[3]['
  795.     dc.b    'STinG skeleton client/server:|'
  796.     dc.b    '-----------------------------|'
  797.     dc.b    'TRANSPORT driver is missing !]'
  798.     dc.b    '[ Abort ]',NUL
  799. ;
  800. layer_not_valid_al_s:
  801.     dc.b    '[3]['
  802.     dc.b    'STinG  T_SetClk time client: |'
  803.     dc.b    '-----------------------------|'
  804.     dc.b    'MODULE driver is missing !]'
  805.     dc.b    '[ Abort ]',NUL
  806.     even
  807. ;
  808. ;
  809. ;Enter program constant definitions below:
  810. ;
  811. daytime_tcp_h:    dc.w    -1
  812. daytime_udp_h:    dc.w    -1
  813. nettime_tcp_h:    dc.w    -1
  814. nettime_udp_h:    dc.w    -1
  815. GMT_f:        dc.w    0
  816. ;
  817. weekday_spt:
  818.     dc.l    sunday_s,monday_s,tuesday_s,wednesday_s
  819.     dc.l    thursday_s,friday_s,saturday_s,sunday_s
  820. ;
  821. sunday_s:    dc.b    'Sunday',NUL
  822. monday_s:    dc.b    'Monday',NUL
  823. tuesday_s:    dc.b    'Tuesday',NUL
  824. wednesday_s:    dc.b    'Wednesday',NUL
  825. thursday_s:    dc.b    'Thursday',NUL
  826. friday_s:    dc.b    'Friday',NUL
  827. saturday_s:    dc.b    'Saturday',NUL
  828. ;
  829. GMT_s:        dc.b    '  GMT  ',NUL
  830. Local_s:    dc.b    ' Local ',NUL
  831. GMT_tail_s:    dc.b    '  GMT',NUL
  832. ;
  833. hello_there_al_s:
  834.     dc.b    '[0]['
  835.     dc.b    'STinG Timeserver Version 1.00|'
  836.     dc.b    '-----------------------------|'
  837.     dc.b    'Active ports in upper case:  |'
  838.     dc.b    'Day time port 13:  '
  839. day_udp_s:
  840.     dc.b                       'UDP  '
  841. day_tcp_s:
  842.     dc.b                            'TCP  |'
  843.     dc.b    'Net time port 37:  '
  844. net_udp_s:
  845.     dc.b                       'UDP  '
  846. net_tcp_s:
  847.     dc.b                            'TCP  ]'
  848.     dc.b    '[ Ok | Time ]',NUL
  849. ;
  850. no_ports_open_al_s:
  851.     dc.b    '[3]['
  852.     dc.b    'STinG Timeserver Version 1.00|'
  853.     dc.b    '-----------------------------|'
  854.     dc.b    'Attempts to open port failed,|'
  855.     dc.b    'both for UDP and TCP !]'
  856.     dc.b    '[ Abort ]',NUL
  857. ;
  858. must_be_GEM_al_s:
  859.     dc.b    '[3]['
  860.     dc.b    'STinG Timeserver Version 1.00|'
  861.     dc.b    '-----------------------------|'
  862.     dc.b    'T_SERVER needs to use GEM, so|'
  863.     dc.b    'TOS/TTP use does not work.]'
  864.     dc.b    '[ Abort ]',NUL
  865. ;
  866. must_be_multi_al_s:
  867.     dc.b    '[3]['
  868.     dc.b    'STinG Timeserver Version 1.00|'
  869.     dc.b    '-----------------------------|'
  870.     dc.b    'In singletasking TOS T_SERVER|'
  871.     dc.b    'can only run as an ACCessory!]'
  872.     dc.b    '[ Abort ]',NUL
  873. ;
  874. ;
  875. ;----------------------------------------------------------------------------
  876. ;
  877. data_limit:    .bss
  878. ;
  879. ;----------------------------------------------------------------------------
  880. ;Enter program variable definitions below:
  881. ;
  882. sting_drivers:    ds.l    1    ;DRV_LIST    *sting_drivers;
  883. tpl:        ds.l    1    ;TPL        *tpl;
  884. stx:        ds.l    1    ;STX        *stx;
  885. initerr_mess_p:    ds.l    1
  886. fatal_f:    ds.w    1
  887. VA_START_f:    ds.w    1
  888. VA_START_cmd_p:    ds.l    1
  889. VA_protostatus:    ds.l    1
  890. ;
  891. tcon_data:    ds.b    sizeof_tcon
  892. buffer:        ds.l    BUF_SIZE
  893. ;
  894. ;----------------------------------------------------------------------------
  895. bss_limit:    .end
  896. ;----------------------------------------------------------------------------
  897. ;End of file:    T_SERVER.S
  898. ;----------------------------------------------------------------------------
  899.